package logic

import (
	"context"
	"strconv"

	"server-go/rpc/reward/internal/models"
	"server-go/rpc/reward/internal/svc"
	"server-go/rpc/reward/types/reward"

	"github.com/zeromicro/go-zero/core/logx"
)

type AdminChangeAuditLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAdminChangeAuditLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AdminChangeAuditLogic {
	return &AdminChangeAuditLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *AdminChangeAuditLogic) AdminChangeAudit(in *reward.AdminChangeAuditInput) (*reward.AdminChangeAuditOutput, error) {
	out := &reward.AdminChangeAuditOutput{Status: 400, Msg: "no have task"}
	audit, _ := strconv.ParseInt(in.Audit, 10, 64)
	if in.Id == 0 {
		return out, nil
	}
	tx := l.svcCtx.Db.Begin()
	taskDao := &models.TasksDao{Id: int(in.Id), Audit: int(audit)}
	if err := taskDao.AdminChangeAuditUpdate(tx); err != nil {
		tx.Rollback()
		return out, err
	}
	tx.Commit()
	out.Status = 200
	out.Msg = "success"
	return out, nil
}
